/*
 * chunk_protocol.h
 *
 *  Created on: Mar 29, 2013
 *      Author: root
 */

#ifndef CHUNK_PROTOCOL_H_
#define CHUNK_PROTOCOL_H_

#include "chunk.h"

/**
 * chunk_protocol class
 */
class chunk_protocol {
public:
	chunk_protocol();
	virtual ~chunk_protocol();

	/*
	*struct trans chunk ,by chunk data,
	*return trans total length,
	* if flag == TRUE :chunk header and data
	* else flag != TRUE: only data but not header
	*/
	static size_t struct_trans_chunk(pchunk pck,uint8_t * pBuf,size_t buf_len,ulong & offset,int flag = TRUE);

	/*
	* seek chunk by trans chunk data stream
	* return :int
	* < 0,seek chunk error,must close
	* == 0,chunk data no complete,
	* == 1,get a completed chunk
	*/
	static int seek_chunk(pchunk pck,uint8_t * pBuf,size_t buf_len);

	/*
	*check  has been a completed chunk,header and data,in the first pos of the buf data
	*/
	static bool is_has_completed_chunk(uint8_t * pBuf,size_t buf_len);
};

#endif /* CHUNK_PROTOCOL_H_ */
